package il.ac.technion;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Handles requests for the application home page.
 */
@Controller
@RequestMapping(value = "/table/*")
public class TableController {
	@Autowired
	private TableDao tableDao;

	@RequestMapping(value = "add", method = RequestMethod.GET, params = { "size" })
	public String add(Model m, Table t) {
		m.addAttribute("type", "table");
		m.addAttribute("cmd", "add");

		if (t.getSize() <= 0) {
			m.addAttribute("errorMsg", "Size of table must be positive");
			return "update_error";
		}

		tableDao.saveObject(t);

		return "update_success";
	}
}
